<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>
          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="dsssId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >
          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space v-permission="['PROPERTY_DEVICELIST_MGR_SLURRY_STATEDATA_DEL_BUTTON']">
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>
            <template v-if="column.key === 'forwardJiecuStatusColumn'">
              <a-tag v-if="record.forwardJiecuStatus == 1" color="green">接通</a-tag>
              <a-tag v-else color="red">断开</a-tag>
            </template>

            <template v-if="column.key === 'reverseJiecuStatusColumn'">
              <a-tag v-if="record.reverseJiecuStatus == 1" color="green">接通</a-tag>
              <a-tag v-else color="red">断开</a-tag>
            </template>

            <template v-if="column.key === 'forwardHotjiecuStatusColumn'">
              <a-tag v-if="record.forwardHotjiecuStatus == 1" color="green">接通</a-tag>
              <a-tag v-else color="red">断开</a-tag>
            </template>

            <template v-if="column.key === 'reverseHotjiecuStatusColumn'">
              <a-tag v-if="record.reverseHotjiecuStatus == 1" color="green">接通</a-tag>
              <a-tag v-else color="red">断开</a-tag>
            </template>

            <template v-if="column.key === 'forwardTripStatusColumn'">
              <a-tag v-if="record.forwardTripStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>

            <template v-if="column.key === 'reverseTripStatusColumn'">
              <a-tag v-if="record.reverseTripStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>
            <template v-if="column.key === 'forwardAutorunStatusColumn'">
              <a-tag v-if="record.forwardAutorunStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>
            <template v-if="column.key === 'reverseAutorunStatusColumn'">
              <a-tag v-if="record.reverseAutorunStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>
            <template v-if="column.key === 'forwardHandrunStatusColumn'">
              <a-tag v-if="record.forwardHandrunStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>
            <template v-if="column.key === 'reverseHandrunStatusColumn'">
              <a-tag v-if="record.reverseHandrunStatus == 1" color="green">开</a-tag>
              <a-tag v-else color="red">关</a-tag>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>
  </div>
</template>

<script>
import { message } from 'ant-design-vue';
import {DeviceSlurryScraperStateApi} from "@/api/property/slurryscraper/DeviceSlurryScraperStateApi";
export default {
  name: 'DeviceSlurryscraperState',
  components: {
  },
  async mounted() {
  },
  props: {
    data: Object
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '设备id',
          dataIndex: 'recordId'
        },
        {
          title: '创建时间',
          dataIndex: 'createTime'
        },
        {
          title: '正转接触器接通状态',
          dataIndex: 'forwardJiecuStatus',
          key : 'forwardJiecuStatusColumn'
        },
        {
          title: '反向转接触器接通状态',
          dataIndex: 'reverseJiecuStatus',
          key : 'reverseJiecuStatusColumn'
        },
        {
          title: '正转热继电器接通状态 ',
          key : 'forwardHotjiecuStatusColumn'
        },
        {
          title: '反转热继电器接通状态',
          key : 'reverseHotjiecuStatusColumn'
        },
        {
          title: '正向行程开关状态',
          key : 'forwardTripStatusColumn'
        },
        {
          title: '反向行程开关状态',
          key : 'reverseTripStatusColumn'
        },
        {
          title: '旋钮给定正转自动运行',
          key : 'forwardAutorunStatusColumn'
        },
        {
          title: '旋钮给定反转自动运行',
          key : 'reverseAutorunStatusColumn'
        },
        {
          title: '旋钮给定正转手动运行',
          key : 'forwardHandrunStatusColumn'
        },
        {
          title: '旋钮给定反转手动运行',
          key : 'reverseHandrunStatusColumn'
        },
        {
          title: '控制器正转输出是否有效',
          dataIndex : 'forwardOutputStatus',
          customRender: function(row) {
            if (row.text == 1) {
              return "是";
            } else {
              return "否";
            }
          }
        },
        {
          title: '控制器反转输出是否有效',
          dataIndex : 'reverseOutputStatus',
          customRender: function(row) {
            if (row.text == 1) {
              return "是";
            } else {
              return "否";
            }
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 200,
          align: 'center',
        }
      ],
      // 表格搜索条件
      where: {"recordId" : this.data.recordId},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/03/29 22:49
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/03/29 22:49
     */
    reset() {
      this.where.recordId = this.data.recordId;
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2022/03/29 22:49
     */
    async remove(row) {
      const result = await DeviceSlurryScraperStateApi.delete({ dsssId: row.dsssId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return DeviceSlurryScraperStateApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
